package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.model.AppraisalOrderModel;
import com.future.mayi.utils.PriceUtils;
import com.future.mayi.view.AppraisalOrderGoodsItemView;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AppraisalAllOrderAdapter extends BaseRecyclerViewAdapter<AppraisalOrderModel> {
    private int style;

    public AppraisalAllOrderAdapter(Context context, XRecyclerView recyclerView, int style) {
        super(context, null, recyclerView);
        this.style = style;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getView(parent, R.layout.layout_appraisal_order_item));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        AppraisalOrderModel model = getItem(position);
        ViewHolder holder = (ViewHolder) viewHolder;
        if (mOnItemClickListener != null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItem(v, position);
                }
            });
            holder.tvEnter.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItem(v, position);
                }
            });
        }
        setText(holder.tvOrderCode, (style == 1 ? "鉴定" : "养护") + "编号：" + model.getOrder_no());
        setText(holder.tvPrice, PriceUtils.getPriceText2(model.getPay_price()));
        holder.orderView.setGoods_item(model.getGoods_item());

        switch (model.getStatus()) {
            // 0-待付款
            case 0:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "立即支付");
                setText(holder.tvState, "待付款");
                break;
            // 10-待寄件
            case 10:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "填写寄件");
                setText(holder.tvState, "待寄件");
                break;
            //11-待养护/鉴定
            case 11:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "查物流");
                setText(holder.tvState, "待".concat(style == 1 ? "鉴定" : "养护"));
                break;
            // 20-待收货
            case 20:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "确认收货");
                setText(holder.tvState, "待收货");
                break;
            // 30-待评价
            case 30:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "立即评价");
                setText(holder.tvState, "待评价");
                break;
            // 40-已完成
            case 40:
                holder.tvEnter.setVisibility(View.GONE);
                setText(holder.tvState, "已完成");
                break;
            // 50-退款申请中
            case 50:
                holder.tvEnter.setVisibility(View.GONE);
                setText(holder.tvState, "退款审核中");
                break;
            // 51-退款已拒绝
            case 51:
                holder.tvEnter.setVisibility(View.GONE);
                setText(holder.tvState, "退款被拒绝");
                break;
            // 60 -退款成功
            case 60:
                holder.tvEnter.setVisibility(View.GONE);
                setText(holder.tvState, "退款成功");
                break;
            // 90-已取消
            case 90:
                holder.tvEnter.setVisibility(View.GONE);
                setText(holder.tvState, "已取消");
                break;
        }


    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_order_code)
        TextView tvOrderCode;
        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.order_view)
        AppraisalOrderGoodsItemView orderView;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_enter)
        TextView tvEnter;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
